package codeTop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class q50 {
    public double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        long nl = n;
        if (n < 0) {
            x = 1/x;
            nl = -nl;
        }
        return func(x,nl);
    }

    private double func(double x, long n) {
        if (n == 1) {
            return x;
        }
        double v = func(x, n / 2);
        double res = 0;
        if (n % 2 == 0) {
            res = v*v;
        }else {
            res = v*v*x;
        }
        return res;
    }

}
